package com.toprs.base.result

import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "返回结果")
data class Result<T>(

    @Schema(description = "状态码")
    val code: Int,

    @Schema(description = "返回信息")
    val msg: String,

    @Schema(description = "返回数据")
    val data: T?
) {

    companion object {

        fun <T> success(data: T): Result<T> {
            return Result(200, "success", data)
        }

        fun successMsg(msg: String): Result<Unit> {
            return Result(200, msg, null)
        }

        fun error(msg: String): Result<String> {
            return Result(500, msg, null)
        }
    }
}